const path = require("path");
const { VueLoaderPlugin } = require("vue-loader");
const HtmlWebpackPlugin = require("html-webpack-plugin");

module.exports = {
  mode: "production",
  entry: "./src/main.js",
  output: {
    path: path.resolve(__dirname, "dist"),
    filename: "index.js",
  },
  module: {
    rules: [
      {
        test: /\.css$/i,
        // 如果同时使用了多个转换器，那么需要将先用的写在后面
        use: ["style-loader", "css-loader"],
      },
      {
        test: /\.less$/i,
        use: [
          // compiles Less to CSS
          "style-loader",
          "css-loader",
          "less-loader",
        ],
      },
      {
        test: /\.vue$/,
        loader: "vue-loader",
      },
    ],
  },
  plugins: [
    // 请确保引入这个插件！
    new VueLoaderPlugin(),
    new HtmlWebpackPlugin({
      // 指定哪个html
      template: path.resolve(__dirname, "./src/public/index.html"),
      filename: "./index.html",
    }),
  ],
  devServer: {
    port: 5173,
    open: true,
    // 用来做反向代理的
    proxy: {
      // key是路径的第一段
      "/api": {
        // target改成协议和域名
        target: "https://i.maoyan.com",
        changeOrigin: true,
      },
    },
  },
  resolve: {
    alias: {
      "@": path.resolve(__dirname, "src/"),
    },
    extensions: [".js", ".json", ".wasm", ".vue"],
  },
};
